package com.lb.action;

import java.util.List;

import javax.servlet.ServletRequest;

import org.apache.struts2.ServletActionContext;

import com.lb.bean.Message;
import com.lb.bean.Reply;
import com.lb.service.MessageService;
import com.opensymphony.xwork2.ActionSupport;

public class DeleteMessage1Action extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private MessageService service;
	private List<Message> allMessage;
    private List<Reply> replylist;
    
	public List<Reply> getReplylist() {
		return replylist;
	}

	public void setReplylist(List<Reply> replylist) {
		this.replylist = replylist;
	}

	private Message ms;

	public Message getMs() {
		return ms;
	}

	public void setMs(Message ms) {
		this.ms = ms;
	}



	public List<Message> getAllMessage() {
		return allMessage;
	}

	public void setAllMessage(List<Message> allMessage) {
		this.allMessage = allMessage;
	}

	public MessageService getService() {
		return service;
	}

	public void setService(MessageService service) {
		this.service = service;
	}

	public String execute() throws Exception {
		this.clearActionErrors();

		ServletRequest request = ServletActionContext.getRequest();
		int messageId = Integer.parseInt(request.getParameter("messageId"));
		
		
		ms = this.service.findmessageById(messageId);
        replylist=this.service.findreplyBymessageId(messageId);
       
		this.service.delete(ms);
		this.service.delete(replylist);
		allMessage=this.service.findAllMessage();
		return SUCCESS;

	}
}
